#include<bits/stdc++.h>
using namespace std;
int n;
int a[20001];
string s;
void bin(int x){
    s="";
    int t=x;
    while(t){
        s+=to_string(t%2);
        t/=2;
    }
}
int main(){

    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while(t--)
    {
    memset(a,0,sizeof(a));
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    int maxc=0,c=0,l=0;
    for(int i=0;i<=1<<(n+1)-1;i++){
       bin(i);
       for(int j=1;j<=s.size();j++){
          if(s[j-1]!='1')continue;
          if(a[j]==l)c+=l;
          l=a[j];
       }
       l=0;
       int c2=0;
       for(int j=1;j<=s.size();j++){
          if(s[j-1]!='0')continue;
          if(a[j]==l)c2+=l;
          l=a[j];
       }
       //cout<<c<<" "<<c2<<" "<<s<<endl;
       c+=c2;
       maxc=max(maxc,c);
       c=0,l=0;
    }
    cout<<maxc<<endl;
    }
    return 0;
}
